USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Groups_Permissions-Insert]    Script Date: [[20120914064955]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064955]]
-- Description:	Insert record into table [dbo].[Groups_Permissions]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Groups_Permissions-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Groups_Permissions-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Groups_Permissions-Insert]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@Group_ID uniqueidentifier =Null  , 
	@Permission_ID uniqueidentifier =Null  , 
	@Group_Permission_TimeStamp timestamp =Null OUTPUT*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Groups_Permissions](/*[ID], [Group_ID], [Permission_ID]*/)
	VALUES     (/*@ID, @Group_ID, @Permission_ID*/)

	/*SELECT @RowNumber = [RowNumber], @Group_Permission_TimeStamp = [Group_Permission_TimeStamp]
    FROM [dbo].[Groups_Permissions]
    WHERE  ( [ID] =@ID )
	AND  ( [Group_ID] =@Group_ID )
	AND  ( [Permission_ID] =@Permission_ID )*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Groups_Permissions-update]    Script Date: [[20120914064955]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064955]]
-- Description:	Update record in table [dbo].[Groups_Permissions]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Groups_Permissions-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Groups_Permissions-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Groups_Permissions-update]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@Group_ID uniqueidentifier =Null  , 
	@Permission_ID uniqueidentifier =Null  , 
	@Group_Permission_TimeStamp timestamp =Null OUTPUT , 
	@OldTimeStamp timeStamp OUTPUT*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/*SELECT @OldTimeStamp = [Group_Permission_TimeStamp]
    FROM [dbo].[Groups_Permissions]
    	WHERE ([ID] = @ID)

    IF  @OldTimeStamp = @Group_Permission_TimeStamp
    BEGIN*/
		Update [dbo].[Groups_Permissions] SET 
		/*[ID] =@ID, 
		[Group_ID] =@Group_ID, 
		[Permission_ID] =@Permission_ID*/
		/*WHERE ([ID] = @ID)*/
	/*END*/

	/*SELECT @RowNumber = [RowNumber], @Group_Permission_TimeStamp = [Group_Permission_TimeStamp]
    FROM [dbo].[Groups_Permissions]
	WHERE ([ID] = @ID)*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Groups_Permissions-Insert-Update]    Script Date: [[20120914064955]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064955]]
-- Description:	Insert OR Update record into table [dbo].[Groups_Permissions]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Groups_Permissions-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Groups_Permissions-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Groups_Permissions-Insert-Update]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@Group_ID uniqueidentifier =Null  , 
	@Permission_ID uniqueidentifier =Null  , 
	@Group_Permission_TimeStamp timestamp =Null OUTPUT , 
	@Inserted bit OUTPUT , 
	@OldTimeStamp timeStamp OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Groups_Permissions] 
					/*WHERE ([ID] = @ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Groups_Permissions](/*[ID], [Group_ID], [Permission_ID]*/)
		VALUES     (/*@ID, @Group_ID, @Permission_ID*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/*SELECT @OldTimeStamp = [Group_Permission_TimeStamp]
		FROM [dbo].[Groups_Permissions]
    	WHERE ([ID] = @ID)

		IF  @OldTimeStamp = @Group_Permission_TimeStamp
		BEGIN*/
			Update [dbo].[Groups_Permissions] SET 
			/*[ID] =@ID, 
			[Group_ID] =@Group_ID, 
			[Permission_ID] =@Permission_ID*/
			/*WHERE ([ID] = @ID)*/
		/*END*/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @RowNumber = [RowNumber], @Group_Permission_TimeStamp = [Group_Permission_TimeStamp]
    FROM [dbo].[Groups_Permissions]
	WHERE ([ID] = @ID)*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Groups_Permissions-Delete]    Script Date: [[20120914064955]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064955]]
-- Description:	delete records from table [dbo].[Groups_Permissions] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Groups_Permissions-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Groups_Permissions-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Groups_Permissions-Delete]
	/*@RowNumber int =null  , 
	@ID uniqueidentifier =null  , 
	@Group_ID uniqueidentifier =null  , 
	@Permission_ID uniqueidentifier =null  , 
	@Group_Permission_TimeStamp timestamp =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Groups_Permissions]
	WHERE /*( [RowNumber] = ISNULL(@RowNumber, [RowNumber]) )
	AND ( [ID] = ISNULL(@ID, [ID]) )
	AND ( [Group_ID] = ISNULL(@Group_ID, [Group_ID]) )
	AND ( [Permission_ID] = ISNULL(@Permission_ID, [Permission_ID]) )
	AND ( [Group_Permission_TimeStamp] = ISNULL(@Group_Permission_TimeStamp, [Group_Permission_TimeStamp]) )*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Groups_Permissions-Select]    Script Date: [[20120914064955]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064955]]
-- Description:	select records from table [dbo].[Groups_Permissions] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Groups_Permissions-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Groups_Permissions-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Groups_Permissions-Select]
	/*@RowNumber int =null  , 
	@ID uniqueidentifier =null  , 
	@Group_ID uniqueidentifier =null  , 
	@Permission_ID uniqueidentifier =null  , 
	@Group_Permission_TimeStamp timestamp =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Groups_Permissions]
	WHERE /*( [RowNumber] = ISNULL(@RowNumber, [RowNumber]) )
	AND ( [ID] = ISNULL(@ID, [ID]) )
	AND ( [Group_ID] = ISNULL(@Group_ID, [Group_ID]) )
	AND ( [Permission_ID] = ISNULL(@Permission_ID, [Permission_ID]) )
	AND ( [Group_Permission_TimeStamp] = ISNULL(@Group_Permission_TimeStamp, [Group_Permission_TimeStamp]) )*/
END
GO
-- =============================================
